import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import UserUtils from '../utils/userUtils'

Vue.use(VueRouter)

  const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta:{
      isShow:true
    }
  },
  {
    path: '/class',
    name: 'Class',
    component: () => import('../views/Class.vue'),
    meta:{
      isShow:true
    }
  },
  {
    path: '/personal',
    name: 'Personal',
    component: () => import('../views/Personal.vue'),
    meta:{
      isShow:true
    }
  },
  {
    path: '/shopping',
    name: 'Shopping',
    component: () => import('../views/Shopping.vue'),
    meta:{
      isShow:false
    }
  },
  {
    path: '/kanjia',
    name: 'Kanjia',
    component: () => import('../views/Kanjia.vue'),
    meta:{
      isShow:false
    }
  },{
    path: '/zhuanti',
    name: 'Zhuanti',
    component: () => import('../views/Zhuanti.vue'),
    meta:{
      isShow:false
    }
  },{
    path: '/specialXiang',
    name: 'SpecialXiang',
    component: () => import('../components/home/special/SpecialXiang.vue'),
    meta:{
      isShow:false
    }
  },{
    path: '/recommend-tui',
    name: 'Recommend-tui',
    component: () => import('../components/home/recommend/Recommend-tui.vue'),
    meta:{
      isShow:false
    }
  },{
    path: '/recommend-shopping-xiang',
    name: 'Recommend-shopping-xiang',
    component: () => import('../components/home/recommend/Recommend-shopping-xiang'),
    meta:{
      isShow:false
    }
  },{
    path: '/login',
    name: 'Login',
    component: () => import('../components/Personal/Login'),
    meta:{
      isShow:false
    }
  },{
    path: '/address',
    name: 'Address',
    component: () => import('../components/Personal/Address'),
    meta:{
      isShow:false
    },
    beforeEnter: (to, from, next) => {
      if(UserUtils.isLogin()==true){
        next()
      }else{
        next('/login')
      }
    }
  },{
    path: '/comment',
    name: 'Comment',
    component: () => import('../components/Personal/Comment'),
    meta:{
      isShow:false
    },
    beforeEnter: (to, from, next) => {
      if(UserUtils.isLogin()==true){
        next()
      }else{
        next('/login')
      }
    }
  },{
    path: '/coupon',
    name: 'Coupon',
    component: () => import('../components/Personal/Coupon'),
    meta:{
      isShow:false
    },
    beforeEnter: (to, from, next) => {
      if(UserUtils.isLogin()==true){
        next()
      }else{
        next('/login')
      }
    }
  },{
    path: '/order',
    name: 'Order',
    component: () => import('../components/Personal/Order'),
    meta:{
      isShow:false
    },
    beforeEnter: (to, from, next) => {
      if(UserUtils.isLogin()==true){
        next()
      }else{
        next('/login')
      }
    }
  },{
    path: '/classshopping',
    name: 'Classshopping',
    component: () => import('../components/class/Classshopping'),
    meta:{
      isShow:false
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
